package com.ticket.sass.admin.controller;


import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import com.ticket.sass.admin.annotation.Loggable;
import com.ticket.sass.admin.annotation.Module;
import com.ticket.sass.admin.business.CouponBusiness;
import com.ticket.sass.admin.dto.input.coupons.CouponAddInput;
import com.ticket.sass.admin.dto.input.coupons.CouponListInput;
import com.ticket.sass.admin.dto.input.coupons.CouponUpdInput;
import com.ticket.sass.admin.dto.output.coupons.CouponListOutput;
import com.ticket.sass.admin.dto.output.coupons.CouponOutput;
import com.ticket.sass.admin.model.PageModel;
import com.ticket.sass.admin.model.ResultModel;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * <p>
 * 优惠券表 前端控制器
 * </p>
 *
 * @author ywb
 * @since 2024-03-13
 */
@RestController
@AllArgsConstructor
@Api(tags = {"优惠券-模块"})
@ApiSupport(order = 9)
@RequestMapping("/coupons")
public class CouponController {
    final CouponBusiness business;
    
    @ApiOperation("列表")
    @GetMapping
    public ResultModel<PageModel<CouponListOutput>> list(
        @Valid CouponListInput input
    ) {
        return ResultModel.success(
            business.list(input)
        );
    }
    
    @ApiOperation("详情")
    @GetMapping("/{id}")
    public ResultModel<CouponOutput> find(
        @PathVariable Long id
    ) {
        return ResultModel.success(
            business.find(id)
        );
    }
    
    @Loggable(module = Module.COUPON, desc = "新增优惠券")
    @ApiOperation("新增优惠券")
    @PostMapping
    public ResultModel<String> add(
        @RequestBody @Valid CouponAddInput input
    ) {
        business.add(input);
        return ResultModel.success();
    }
    
    @Loggable(module = Module.COUPON, desc = "修改优惠券")
    @ApiOperation("修改优惠券")
    @PutMapping
    public ResultModel<String> upd(
        @RequestBody @Valid CouponUpdInput input
    ) {
        business.upd(input);
        return ResultModel.success();
    }
}
